package cn.jly.flink.operators;

import cn.jly.flink.entity.Employee;
import cn.jly.flink.utils.ConstantUtils;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.ExecutionEnvironment;

import java.math.BigDecimal;

/**
 * @PackageName cn.jly.flink.operators
 * @ClassName MapDemo
 * @Description 测试map算子
 * @Author 姬岚洋
 * @Date 2021/1/8 下午 4:32
 */
public class MapDemo {
    public static void main(String[] args) throws Exception {

        final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        env.fromElements(
                new Employee(ConstantUtils.ID_GENERATOR.getAndIncrement(), "tom", BigDecimal.valueOf(10000)),
                new Employee(ConstantUtils.ID_GENERATOR.getAndIncrement(), "lily", BigDecimal.valueOf(20000)),
                new Employee(ConstantUtils.ID_GENERATOR.getAndIncrement(), "james", BigDecimal.valueOf(30000))
        )
                .map(new MapFunction<Employee, Employee>() {
                    @Override
                    public Employee map(Employee employee) throws Exception {
                        // double salary
                        employee.setSalary(employee.getSalary().multiply(BigDecimal.valueOf(2)));
                        return employee;
                    }
                })
                .print();
    }
}
